package UserView;

import Model.Student;
import Service.ServiceImpl.StudentServiceImpl;
import Service.StudentService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class UserUi {
    public static int num =0;
    public static int id =1;
    public void UI() {
        Student[] stus = new Student[100];
        StudentServiceImpl studentService = new StudentServiceImpl();

        boolean flag = true;
        while (flag) {
            System.out.println("1.查询所有的学生信息");
            System.out.println("2.添加学生信息");
            System.out.println("3.删除学生信息");
            System.out.println("4.修改学生信息");
            System.out.println("0.退出系统");
            System.out.println("亲，输入你所需要的业务序号");
            Scanner scanner = new Scanner(System.in);
            int num = scanner.nextInt();
            switch (num) {
                case 1:
                    studentService.showStu(stus, UserUi.num);
                    break;
                case 2:
                    Student zhang = new Student();
                    System.out.println("请输入学生的姓名");
                    String name = scanner.next();
                    System.out.println("请输入学生的性别");
                    String sex = scanner.next();
                    System.out.println("请输入学生的年龄");
                    Integer age = scanner.nextInt();
                    System.out.println("请输入学生的专业");
                    String major = scanner.next();
                    zhang.setId(UserUi.id++);
                    zhang.setName(name);
                    zhang.setSex(sex);
                    zhang.setAge(age);
                    zhang.setMajor(major);
                    Date date = new Date();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mmmm-dd hh:mm:ss");
                    String format = simpleDateFormat.format(date);
                    zhang.setTime(format);
                    studentService.addStu(stus, zhang);
                    break;
                case 3:
                    System.out.println("请输入你要删除的学号");
                    int stuId =scanner.nextInt();
                    boolean b =studentService.delStu(stus,UserUi.num,stuId);
                   if (b){
                       System.out.println("删除成功");
                       UserUi.num--;
                   }else {
                       System.out.println("删除不存在");
                   }
                    break;
                case 4:
                    System.out.println("请输入你要修改的学号");
                    int stuId1 = scanner.nextInt();
                    studentService.updateStu(stus,UserUi.num,stuId1);
                    System.out.println("修改成功");
                break;
                case 0:
                    System.out.println("退出系统");
                    flag = false;
                    break;
            }
        }
    }
}
